Numerik

Ingenieurinformatik Teil 2, Sommersemester 2026

David Straub

Numerik – D. Straub

Gliederung

  1. Einführung in Matlab
  2. Arbeiten mit Arrays
  3. Funktionen und Kontrollstrukturen
  4. Analysis
  5. Lineare Algebra 👈
  6. Differentialgleichungen
  7. Einführung in Simulink
Numerik – D. Straub

Fahrplan – 2 Einheiten

Einheit 1 (heute): Lineare Gleichungssysteme

  • Motivation
  • Matrixoperationen in Matlab
  • Lineare Gleichungssysteme: Formen, Rang, Konditionierung
  • Lösung mit \ – wann exakt, wann Least-Squares?

Einheit 2: Eigenwertprobleme

  • Eigenwerte und Eigenvektoren: eig
  • Physikalische Interpretation
  • Anwendung: Gekoppelte Schwingungen
  • Verallgemeinertes Eigenwertproblem
Numerik – D. Straub

Motivation: Ein Ingenieurproblem

Numerik – D. Straub

Batteriezellen parallel schalten

Drei Batteriezellen mit unterschiedlichen Spannungen U1,U2,U3U_1, U_2, U_3 und Innenwiderständen R1,R2,R3R_1, R_2, R_3 werden parallel geschaltet.

Gesucht: Ströme I1,I2,I3I_1, I_2, I_3 durch jede Zelle.

Numerik – D. Straub

Kirchhoffsche Gesetze

Maschenregel (für jede Zelle):

U1I1R1I0R0=0U_1 - I_1 R_1 - I_0 R_0 = 0

U2I2R2I0R0=0U_2 - I_2 R_2 - I_0 R_0 = 0

U3I3R3I0R0=0U_3 - I_3 R_3 - I_0 R_0 = 0

Knotenregel:

I1+I2+I3=I0I_1 + I_2 + I_3 = I_0

4 Gleichungen, 4 Unbekannte → Lineares Gleichungssystem!

Numerik – D. Straub

Als Matrixgleichung

(R100R00R20R000R3R01111)(I1I2I3I0)=(U1U2U30)\begin{pmatrix} R_1 & 0 & 0 & R_0 \\ 0 & R_2 & 0 & R_0 \\ 0 & 0 & R_3 & R_0 \\ 1 & 1 & 1 & -1 \end{pmatrix} \begin{pmatrix} I_1 \\ I_2 \\ I_3 \\ I_0 \end{pmatrix} = \begin{pmatrix} U_1 \\ U_2 \\ U_3 \\ 0 \end{pmatrix}

Kurzform: Ax=bA\boldsymbol{x} = \boldsymbol{b}

Frage: Wie lösen wir das in Matlab effizient?

Numerik – D. Straub

Matrixoperationen

Numerik – D. Straub

Wiederholung: Matrix-Arithmetik

Matrizen sind das zentrale Datenobjekt in Matlab:

A = [1 2; 3 4];
B = [5 6; 7 8];

C = A + B       % Addition
D = A * B       % Matrixmultiplikation (!)
E = A .* B      % Elementweise Multiplikation

Wichtig: * ist die mathematische Matrixmultiplikation!

(1234)(5678)=(19224350)\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} \cdot \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix} = \begin{pmatrix} 19 & 22 \\ 43 & 50 \end{pmatrix}

Numerik – D. Straub

Transposition

A = [1 2 3; 4 5 6]

Punkt-Transposition: Reines Vertauschen von Zeilen/Spalten

A.'       % [1 4; 2 5; 3 6]

Komplex-konjugierte Transposition: Für komplexe Matrizen

A'        % Transponiert UND konjugiert komplex

Für reelle Matrizen sind .' und ' identisch.

Numerik – D. Straub

Matrix-Vektor-Multiplikation

Ein lineares Gleichungssystem Ax=bA\boldsymbol{x} = \boldsymbol{b} ist eine Matrix-Vektor-Multiplikation:

A = [-1  1;
      1  1];
x = [1.5; 3.5];

b = A * x      % b = [2; 5]

(1111)(1.53.5)=(25)\begin{pmatrix} -1 & 1 \\ 1 & 1 \end{pmatrix} \begin{pmatrix} 1.5 \\ 3.5 \end{pmatrix} = \begin{pmatrix} 2 \\ 5 \end{pmatrix}

Numerik – D. Straub

Wichtige Matrixoperationen

A = [1 2; 3 4];

det(A)      % Determinante
inv(A)      % Inverse Matrix
rank(A)     % Rang
cond(A)     % Konditionszahl

Diese Funktionen brauchen wir, um Gleichungssysteme zu verstehen!

Numerik – D. Straub

Lineare Gleichungssysteme

Numerik – D. Straub

Was ist ein lineares Gleichungssystem?

Allgemeine Form:

Ax=bA\boldsymbol{x} = \boldsymbol{b}

  • AA: (m×n)(m \times n)-Matrix (Koeffizientenmatrix)
  • x\boldsymbol{x}: Spaltenvektor mit nn Unbekannten
  • b\boldsymbol{b}: Spaltenvektor mit mm Gleichungen

mm Gleichungen für nn Unbekannte

Numerik – D. Straub

Formen von AA

Quadratisch: m=nm = n (gleich viele Gleichungen wie Unbekannte)

A = [2 1; 1 3];    % 2×2

Überbestimmt: m>nm > n (mehr Gleichungen als Unbekannte)

A = [2 1; 1 3; -1 2];    % 3×2

Unterbestimmt: m<nm < n (weniger Gleichungen als Unbekannte)

A = [2 1 3];    % 1×3
Numerik – D. Straub

Rang einer Matrix

Der Rang rank(A)\text{rank}(A) ist die Anzahl linear unabhängiger Zeilen/Spalten:

A = [1  2  3;
     2  4  6];    % Zeile 2 = 2·Zeile 1

rank(A)           % 1 (nicht 2!)

Bedeutung: Gibt an, wie viele "echte" Gleichungen vorhanden sind.

rank(A)min(m,n)\text{rank}(A) \leq \min(m, n)

Numerik – D. Straub

✍️ Übung: Rang bestimmen

Welchen Rang haben diese Matrizen? Überlegen Sie erst, dann prüfen mit rank():

A1 = [1 2 3; 2 4 6; 1 1 1];
A2 = [1 0 0; 0 1 0; 0 0 1];
A3 = [1 2; 3 6; 2 4];
Numerik – D. Straub

Geometrische Interpretation

2 Gleichungen, 2 Unbekannte: Jede Gleichung = Gerade

x+y=2x+y=5\begin{aligned} -x + y &= 2 \\ x + y &= 5 \end{aligned}

Lösung = Schnittpunkt der Geraden

3 Gleichungen, 3 Unbekannte: Jede Gleichung = Ebene

Lösung = Schnittpunkt der Ebenen

Numerik – D. Straub

Lösbarkeit: Quadratisches System

Für quadratische Systeme (m=nm = n):

Fall 1: det(A)0\det(A) \neq 0 und rank(A)=n\text{rank}(A) = n
Genau eine Lösung für jedes b\boldsymbol{b}

Fall 2: det(A)=0\det(A) = 0 oder rank(A)<n\text{rank}(A) < n (Matrix singulär)
→ Keine Lösung ODER unendlich viele Lösungen

A = [-1  1;
     -2  2];    % Zeile 2 = 2·Zeile 1

det(A)          % 0
rank(A)         % 1
Numerik – D. Straub

Lösbarkeit: Nicht-quadratische Systeme

Überbestimmt (m>nm > n):

  • Falls rank(A)=n\text{rank}(A) = n und b\boldsymbol{b} im Spaltenraum: eine Lösung
  • Sonst: keine exakte Lösung (aber bestmögliche Näherung möglich)

Unterbestimmt (m<nm < n):

  • Falls rank(A)=m\text{rank}(A) = m: unendlich viele Lösungen
  • Sonst: keine Lösung oder unendlich viele
Numerik – D. Straub

Konditionierung

Die Konditionszahl misst, wie empfindlich die Lösung auf Störungen reagiert:

A = [1  1;
     1  1.0001];

cond(A)     % 40000 (schlecht konditioniert!)

Faustregel:

  • κ(A)<100\kappa(A) < 100: gut konditioniert
  • κ(A)>1010\kappa(A) > 10^{10}: schlecht konditioniert
  • κ(A)=\kappa(A) = \infty: singulär

Bedeutung: Bei κ=106\kappa = 10^6 können 6 Dezimalstellen im Ergebnis falsch sein!

Numerik – D. Straub

Singuläre vs. schlecht konditionierte Matrix

% Singulär: det = 0, unendliche Konditionszahl
A1 = [1 2; 2 4];
det(A1)      % 0
cond(A1)     % Inf

% Schlecht konditioniert: det ≠ 0, aber sehr klein
A2 = [1 2; 2 4.001];
det(A2)      % 0.001
cond(A2)     % 16004

Singuläre Matrix: Keine eindeutige Lösung (mathematisches Problem)
Schlecht konditioniert: Lösung existiert, aber numerisch instabil

Numerik – D. Straub

Exakte Lösung vs. Least-Squares

Numerik – D. Straub

Exakte Lösung

Wenn Ax=bA\boldsymbol{x} = \boldsymbol{b} exakt lösbar ist:

A = [2 1; 1 3];
b = [5; 6];

x = ???        % Gesucht!

A * x          % Ergebnis ist EXAKT b

Probe: Axb=0A\boldsymbol{x} - \boldsymbol{b} = \boldsymbol{0}

Numerik – D. Straub

Keine exakte Lösung möglich

Überbestimmtes System – 3 Geraden haben keinen gemeinsamen Schnittpunkt:

A = [-1    1;
      1    1;
     -0.4  1];
b = [0; 2; 0.5];

Keine Lösung erfüllt alle 3 Gleichungen gleichzeitig!

Was tun?

Numerik – D. Straub

Least-Squares-Lösung

Idee: Finde x\boldsymbol{x}, das den Fehler minimiert:

minxAxb2\min_{\boldsymbol{x}} \|A\boldsymbol{x} - \boldsymbol{b}\|^2

x = ???        % Bestmögliche Lösung

residuum = A * x - b     % ≠ 0, aber minimal!
norm(residuum)           % So klein wie möglich

Least-Squares = "Kleinste Quadrate" = Minimiere Summe der quadrierten Fehler

Numerik – D. Straub

Wann exakt, wann Least-Squares?

System Bedingung Lösung
Quadratisch det(A)0\det(A) \neq 0 Exakt
Quadratisch det(A)=0\det(A) = 0 Keine oder \infty viele
Überbestimmt b\boldsymbol{b} im Spaltenraum Exakt (selten!)
Überbestimmt Sonst Least-Squares
Unterbestimmt - \infty viele (min. Norm)
Numerik – D. Straub

Lösung mit Linksdivision \

Numerik – D. Straub

Der Backslash-Operator \

Der universelle Löser für lineare Gleichungssysteme:

A = [-1  1;
      1  1];
b = [2; 5];

x = A \ b           % Lösung: [1.5; 3.5]

Ax=bx=A\bA\boldsymbol{x} = \boldsymbol{b} \quad \Longrightarrow \quad \boldsymbol{x} = A \backslash \boldsymbol{b}

Numerik – D. Straub

\ vs. / – Linksdivision vs. Rechtsdivision

Linksdivision \: Löst Ax=bA\boldsymbol{x} = \boldsymbol{b}

x = A \ b      % "A nach links teilen"

Rechtsdivision /: Löst xA=b\boldsymbol{x}A = \boldsymbol{b}

x = b / A      % "A nach rechts teilen"
               % Äquivalent zu: x = (A' \ b')'

In der Praxis: Fast immer \ verwenden! / nur für spezielle Fälle (z.B. bei transponierten Systemen).

Numerik – D. Straub

Was macht \ genau?

Matlab analysiert AA und wählt den optimalen Algorithmus:

AA Was macht \?
Quadratisch, regulär (m=nm=n, det0\det \neq 0) Exakte Lösung (LU-Zerlegung)
Quadratisch, singulär (m=nm=n, det=0\det = 0) Warnung! Pseudo-Inverse
Überbestimmt (m>nm > n) Least-Squares (QR-Zerlegung)
Unterbestimmt (m<nm < n) Lösung mit m\leq m Nicht-Null-Elementen

Matlab wählt automatisch – aber Sie müssen das Ergebnis überprüfen!

Numerik – D. Straub

Beispiel 1: Quadratisches System (exakt)

A = [-1  1;
      1  1];
b = [2; 5];

x = A \ b      % [1.5; 3.5]

% Probe:
norm(A*x - b)  % 0 → Exakte Lösung!
Numerik – D. Straub

Beispiel 2: Überbestimmtes System (Least-Squares)

A = [-1    1;
      1    1;
     -0.4  1];
b = [0; 2; 0.5];

x = A \ b 

% Probe:
A * x          % ≠ b!
norm(A*x - b)  % ≠ 0 → Keine exakte Lösung!

Matlab gibt automatisch Least-Squares-Lösung!

Numerik – D. Straub

⚠️ Wichtig: Überprüfen Sie die Lösung!

Immer Residuum berechnen:

x = A \ b;
r = A*x - b;
fehler = norm(r);

if fehler < 1e-10
    disp('Exakte Lösung gefunden')
else
    disp('Least-Squares-Lösung (keine exakte Lösung)')
    fprintf('Fehler: %.3e\n', fehler)
end
Numerik – D. Straub

⚠️ Warnung: Singuläre Matrix

A = [1  2;
     2  4];    % Zeile 2 = 2·Zeile 1
b = [3; 4];

det(A)         % 0 (singulär!)
x = A \ b       % Warnung!

Ausgabe:

Warning: Matrix is singular to working precision.
x =
   Inf
  -Inf

Bei Singularität: Matlab warnt und gibt unsinnige Ergebnisse!

Numerik – D. Straub

⚠️ Warnung: Fast singuläre Matrix

A = [1      2;
     2  3.9999999999999995];  % Fast parallel!

det(A)         % -8.88e-16 (fast 0!)
x = A \ b

Ausgabe:

Warning: Matrix is close to singular or badly scaled.
         Results may be inaccurate. RCOND = 1.233581e-17. 
x =
  1.0e+15 *
   -9.0072
    4.5036

Bei schlechter Konditionierung: Kleine Fehler → riesige Ergebnisse!

Numerik – D. Straub

Beispiel: Lösung mit inv (nicht empfohlen!)

A = [-1  1;
      1  1];
b = [2; 5];

% Mit inv (funktioniert, aber ineffizient)
IA = inv(A);
x = IA * b          % [1.5; 3.5]

% Probe
A * x               % [2; 5] ✓
A * IA              % [1 0; 0 1] = Einheitsmatrix
det(A) * det(IA)    % -2 * -0.5 = 1

Aber: Für große Matrizen langsam und ungenau!

Numerik – D. Straub

Zusammenfassung

Numerik – D. Straub

Wichtigste Erkenntnisse

Lineare Gleichungssysteme: Ax=bA\boldsymbol{x} = \boldsymbol{b}

  • Form von AA: quadratisch, überbestimmt, unterbestimmt
  • Rang und Konditionierung bestimmen Lösbarkeit
  • Exakte Lösung vs. Least-Squares

Lösung mit \:

  • Universeller Operator – wählt beste Methode
  • Überprüfen: norm(A*x - b) → 0 bedeutet exakt
  • Nicht inv(A)*b für LGS verwenden!

Matrixfunktionen:

  • det(A), rank(A), cond(A) – Analyse
  • inv(A) – okay für andere Zwecke, nicht für LGS
Numerik – D. Straub